package com.gitee.ly.openfeign;

import com.gitee.ly.DiscoverAndLoadBalanceAutoConfiguration;
import feign.Client;
import feign.Feign;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@ConditionalOnClass({Feign.class, Client.class})
@AutoConfigureAfter(DiscoverAndLoadBalanceAutoConfiguration.class)
@Configuration
public class OpenFeignDiscoverAndLoadBalanceAutoConfiguration {
    @Bean
    public OpenFeignBeanPostProcessor feignContextBeanPostProcessor(BeanFactory beanFactory) {
        return new OpenFeignBeanPostProcessor(beanFactory);
    }

    @Bean
    @Primary
    @ConditionalOnMissingBean
    public LightRegistryFeignClientFinalRequestHandle lightRegistryFeignClientFinalRequestHandle() {
        return new DefaultLightRegistryFeignClientFinalRequestHandle();
    }
}
